def f(x):
    for i in range(2, int(x**0.5)+1):
        if x % i == 0:
            return False
    return True
    
c = ""
k = 0
for i in input().split():
    if i=="zero":
        c+='0'
    elif i=="one":
        c+='1'
    elif i=="two":
        c+='2'
    elif i=="three":
        c+='3'
    elif i=="four":
        c+='4'
    elif i=="five":
        c+='5'
    elif i=="six":
        c+='6'
    elif i=="seven":
        c+='7'
    elif i=="eight":
        c+='8'
    elif i=="nine":
        c+='9'
    else:
        k=1
        break
if k==1 or len(c)!=3:
    print("Wrong input")
else:
    c=int(c)

    m2=0
    m1=0
    
    for i in range(c+1,1000):
        if f(i):
            m1=i
            break
        
    for i in range(c-1,99,-1):
        if f(i):
            m2=i
            break
    
    if c-m2>m1-c:
        print(m1)
    else:
        print(m2)
